# encoding: utf-8
# 更新集成计划的状态

import requests
from app import create_app
from app.modules.integration.models import IntegrationInfo

# 不修改的集成计划id
_ignore = ['IG201807160000000889290001']
_token_id = ''
_plan_ip = '172.16.3.1616'


def updateStatus():
    app = create_app(flask_config = 'development')
    with app.app_context():
        for _in in IntegrationInfo.query.filter_by(integration_status = 'INTEGRATIONING').all():
            # print _in.to_dict()
            if _in.integration_id in _ignore:
                print ('例外 : %s' % _in.integration_name)
                continue
            print ('交付并上线 :%s' % _in.integration_name)
            _url = 'http://' + _plan_ip + ':5003/api/v1/integration/handOverIntegration?token_id=' + _token_id + '&integration_id=' + _in.integration_id
            _rtn = requests.get(url = _url).content
            print '交付 : %s' % _rtn
            _url = 'http://' + _plan_ip + ':5003/api/v1/integration/pigeonholeIntegration?token_id=' + _token_id + '&integration_name=' + _in.integration_name
            _rtn = requests.get(url = _url).content
            print '归档 : %s' % _rtn

        for _in in IntegrationInfo.query.filter_by(integration_status = 'HAND_OVER').all():
            # print _in.to_dict()
            if _in.integration_id in _ignore:
                print ('例外 : %s' % _in.integration_name)
                continue
            print ('上线 :%s' % _in.integration_name)
            _url = 'http://' + _plan_ip + ':5003/api/v1/integration/pigeonholeIntegration?token_id=' + _token_id + '&integration_name=' + _in.integration_name
            _rtn = requests.get(url = _url).content
            print '归档 : %s' % _rtn
        pass

    pass


updateStatus()
